package com.emou.controller;

import com.emou.bean.Register;
import com.emou.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created on 2021/2/2.
 *
 * @author Emou
 */
@Controller
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    @RequestMapping("/getall")
    public String getall(ModelMap modelMap) {
        List<Register> registerList = registerService.selectRegister();
        modelMap.addAttribute("registersList", registerList);
        return "/content/registerTable";
    }

    @RequestMapping("/toAdd")
    public String toAddRegister() {
        return "/content/addRegister";
    }

    @RequestMapping("/add")
    public String addRegister(Register register) {
        registerService.insertRegister(register);
        return "forward:/register/getall";
    }

    @RequestMapping("/deleteRegister/{id}")
    public String deleteRegister(@PathVariable("id") Integer id) {
        registerService.deleteRegister(id);
        return "forward:/register/getall";
    }

    @RequestMapping("/selectRegister/{id}")
    public String selectRegisterById(@PathVariable("id") Integer id,ModelMap modelMap) {
        modelMap.addAttribute("list", registerService.selectRegisterById(id));
        return "/content/registerUpdate";
    }

    @RequestMapping("/update")
    public String updateRegister(ModelMap modelMap, Register register) {
        modelMap.addAttribute("list", register);
        registerService.updateRegister(register);
        return "forward:/register/getall";
    }



}
